<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同编号" :labelCol="labelCol">
              <j-input placeholder="请输入合同编号" v-model="queryParam.finalNo"></j-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同名称" :labelCol="labelCol">
              <j-input placeholder="请输入合同名称" v-model="queryParam.htmc"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号" :labelCol="labelCol">
              <j-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称" :labelCol="labelCol">
              <select-project-input ref="projectModel" v-model="queryParam.xmmc"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业绩归属年度" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择业绩归属年度" v-model="queryParam.yjgsnd" dictCode="yjgsnd"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="签订日期" :labelCol="labelCol">
              <a-range-picker
                format="YYYY-MM-DD"
                :placeholder="['开始日期', '结束日期']"
                v-model="qdrqRange"
                @change="(dates, dateStrs) => { queryParam.qdrq_begin = dateStrs[0]; queryParam.qdrq_end = dateStrs[1] }"
                style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="变更状态" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择合同类型" v-model="queryParam.changeStatus" dictCode="change_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="本次合同额" :labelCol="labelCol">
              <a-input-number
                :precision="2"
                placeholder="请输入最小值"
                class="query-group-cust"
                v-model="queryParam.bchteBegin"
                @change="(val) => this.bchteRange = parseInt(val)"
                style="width: 47%"
                :min="0"
                :max="999999999"/>
              -
              <a-input-number
                :precision="2"
                placeholder="请输入最大值"
                class="query-group-cust"
                v-model="queryParam.bchteEnd"
                style="width: 47%"
                :min="bchteRange"
                :max="999999999"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="签订单位" :labelCol="labelCol">
              <select-Company-input v-model="queryParam.qddw" placeholder="请选择签订单位"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业主单位" :labelCol="labelCol">
              <select-customer-input v-model="queryParam.yzdw" commercialType="1"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="乙方单位" :labelCol="labelCol">
              <SelectSupplierInput
                title="关联乙方单位"
                placeholder="请选择乙方单位"
                v-model="queryParam.khdaId" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经营团队" :labelCol="labelCol">
              <select-team-input v-model="queryParam.jytd" :tdlx="1" :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同档案状态" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择合同档案状态" v-model="queryParam.status" dictCode="contract_final_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="费用类型" :labelCol="labelCol">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.feeType"
                dictCode="fee_type"
                placeholder="请选择费用类型"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人" :labelCol="labelCol">
              <select-user-by-dep :multi="false" v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请部门" :labelCol="labelCol">
              <j-select-depart placeholder="请选申请办部门" v-model="queryParam.handlerDeptId"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px;">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-popover title="自定义列" trigger="click" placement="leftBottom" style="margin-bottom: 10px">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">
                      <!-- {{ item.title }} -->
                      <ellipsis :length="15">{{ item.title }}</ellipsis>
                    </a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="xmmc" slot-scope="text, record" @click="onDetail(record.xmmc)">{{ text }}</a>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <a slot="htmc" :title="text" slot-scope="text, record" @click="getDetail(record.id)">
          {{ text }}
        </a>
      </a-table>
    </div>
    <erp-omc-contract-manager-final-modal ref="modalForm" @ok="modalFormOk"></erp-omc-contract-manager-final-modal>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectModalForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpOmcContractManagerFinalModal from './modules/ErpOmcContractManagerFinalModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import SelectSupplierInput from '@/views/scy/components/selectSupplier/SelectSupplierInput'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import Ellipsis from '@/components/Ellipsis'
import { getAction } from '@/api/manage'
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
export default {
  name: 'ErpOmcContractManagerFinalList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcContractManagerFinalModal,
    SelectCustomerInput,
    SelectTeamInput,
    SelectProjectInput,
    SelectUserByDep,
    BusinessCategoryNameSelect,
    SelectCompanyInput,
    Ellipsis,
    ErpProjectReportModal,
    SelectSupplierInput
  },
  data() {
    return {
      /* 排序参数 */
      isorter: {
        column: '',
        order: ''
      },
      queryParam: {
        htlx: '2' // 付款合同
      },
      description: '合同档案管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          align: 'center',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '合同编号',
          align: 'center',
          dataIndex: 'finalNo',
          ellipsis: true,
          width: 170
        },

        {
          title: '合同名称',
          align: 'center',
          dataIndex: 'htmc',
          ellipsis: true,
          width: 170,
          scopedSlots: { customRender: 'htmc' }
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'xmbh',
          ellipsis: true,
          width: 170
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'xmmc_dictText',
          scopedSlots: { customRender: 'xmmc' },
          ellipsis: true,
          width: 170
        },
        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'yjgsnd_dictText',
          ellipsis: true,
          width: 105
        },
        {
          title: '签订日期',
          align: 'center',
          dataIndex: 'qdrq',
          ellipsis: true,
          width: 90,
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '本次合同额(元)',
          align: 'center',
          dataIndex: 'bchte',
          ellipsis: true,
          width: 115
        },
        {
          title: '费用类型',
          align: 'center',
          dataIndex: 'feeType_dictText',
          ellipsis: true,
          width: 75
        },
        {
          title: '签订单位',
          align: 'center',
          dataIndex: 'qddw_dictText',
          ellipsis: true,
          width: 170
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'yzdw_dictText',
          ellipsis: true,
          width: 170
        },
        {
          title: '乙方单位',
          align: 'center',
          dataIndex: 'enterpriseName',
          ellipsis: true,
          width: 170
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'jytd_dictText',
          ellipsis: true,
          width: 170
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          ellipsis: true,
          width: 75

        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          ellipsis: true,
          width: 120

        },
        {
          title: '变更状态',
          align: 'center',
          dataIndex: 'changeStatus_dictText',
          ellipsis: true,
          width: 75
        },
        {
          title: '合同档案状态',
          align: 'center',
          dataIndex: 'status_dictText',
          ellipsis: true,
          width: 110,
          scopedSlots: { customRender: 'status' }
        }
      ],
      url: {
        list: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/payment/list',
        delete: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/delete',
        deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/deleteBatch',
        exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/exportXls',
        importExcelUrl: 'api/erp/omc/contractmanager/erpOmcContractManagerFinal/importExcel',
        queryProjectById: '/api/erp/project/report/erpProjectReport/queryById'
      },
      dictOptions: {},
      superFieldList: [],
      qdrqRange: [],
      bchteRange: 0
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    getDetail(id) {
      this.$router.push({
        path: `/erp/omc/contractmanager/ErpOmcContractManagerPaymentFinalListDetail/${id}`
      })
    },
    onDetail(id) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.projectModalForm.getDetail(model);
            that.$refs.projectModalForm.title = '项目一览表';
          }
        })
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptCode', text: '经办人部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htbh', text: '合同编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'sfyz', text: '是否用印', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
      fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: '' })
      fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
      fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
      fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
      fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'int', value: 'lx', text: 'lx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz', text: 'bz', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yjxx', text: 'yjxx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xgfj', text: 'xgfj', dictCode: '' })
      this.superFieldList = fieldList
    },
    searchReset() {
      this.qdrqRange = [];
      this.onClearSelected();
      this.queryParam = {
        htlx: '2' // 付款合同
      }
      this.loadData(1)
    },
    businessCategoryHandle(obj) {
      if (obj) {
        this.queryParam.businessCategory = obj.categoryCode;
      }
    }
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
::v-deep {
  .ant-select-selection__rendered {
    width: 90% !important;
    display: inline-grid !important;
  }
}
</style>
